/******************************************************************************
 * * mmi_modem_adaptor_call.c - implementation of mmi-modem adaptor, call sub-module
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "lv_watch.h"

#if USE_LV_WATCH_MODEM_ADAPTOR != 0
#include "mmi_modem_adaptor_call.h"

Modem_Call_Mng_t g_ModemCallMng;

/******************************************************************************
 *
 *         Functions
 *
 *******************************************************************************/
/**
 * initiate mmi-modem adaptor module
 * param (in) void:
 * return  void
 */
VOID MMI_ModemAdp_Call_Init_Req()
{
    UINT8 i;

    g_ModemCallMng.OperatingSim    = modem_sim_id;
    g_ModemCallMng.DualCallPresent = FALSE;
    g_ModemCallMng.BufferHangUp = FALSE;
    g_ModemCallMng.Ccwa = FALSE;
    g_ModemCallMng.RequestDial = FALSE;
    for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
        g_ModemCallMng.CallIndex[i] = MMI_MODEM_CALL_INVALID_INDEX;
    }
    g_ModemCallMng.FgActiveCall = 0xFF;         // 0xFF: Currently no call

    g_ModemCallMng.Imei[MMI_MODEM_SIM_1] = NULL;
    g_ModemCallMng.Imei[MMI_MODEM_SIM_2] = NULL;
    g_ModemCallMng.BasebandVer = NULL;
}

/******************************************************************************
 *
 *         MMI -> Modem Adaptor
 *
 *******************************************************************************/

/**
 * Gets IMEI (#*06#)
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Imei(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Request_Imei_t * pMsg;

    pMsg = (MMI_Modemadp_Call_Request_Imei_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Request_Imei_t));

    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_REQUEST_IMEI, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Get baseband version
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Baseband_Version(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Request_Baseband_Version_t * pMsg;

    pMsg = (MMI_Modemadp_Call_Request_Baseband_Version_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Request_Baseband_Version_t));

    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_REQUEST_BASEBAND_VERSION, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Query Imei
 * param (in) SimId: MMI_MODEM_SIM_ID
         (out) Operator: INT8 *
 * return  void
 */
VOID MMI_Modem_Query_Imei_Req(MMI_MODEM_SIM_ID SimId, INT8 * Imei)
{
    static INT8 tmp_imei[8] = "Unknown";

    printf("##interface## %s\n", __FUNCTION__);

    if(NULL != g_ModemCallMng.Imei[SimId]) {
        strncpy(Imei, g_ModemCallMng.Imei[SimId], 16);
    } else {
        Hal_Mem_Copy(Imei, tmp_imei, 8);
    }
}

/**
 * Get baseband version for ui
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
void MMI_Modem_Call_Query_Baseband_Version(MMI_MODEM_SIM_ID simId ,char* baseband_ver)
{
    static INT8 tmp_baseband_ver[8] = "Unknown";

    printf("##interface## %s\n", __FUNCTION__);

    if(NULL != g_ModemCallMng.BasebandVer) {
        UINT16 len = strlen(g_ModemCallMng.BasebandVer) + 1;
        printf("##interface## %s,len is %d\n", __FUNCTION__,len);
        strncpy(baseband_ver, g_ModemCallMng.BasebandVer, len);
    } else {
        Hal_Mem_Copy(baseband_ver, tmp_baseband_ver, 8);
    }
}

/**
 * Requests current call list ( AT+CLCC)
 * param (out) calls:  MMI_MODEM_CALL_REQUEST_GET_CURRENT_CALLS *
 * return  void
 */
VOID MMI_Modem_Call_Request_Get_Current_Calls(MMI_MODEM_SIM_ID  simId)
{
    RIL_Errno                        RilResult;

    RilResult      = Ril_CC_Request_Get_Current_Calls(MMI_ModemAdp_Get_Ril_SimId(simId));
    g_ModemCallMng.GetCurCallsCau = MODEM_GET_CUR_CALLS_RES;
    g_ModemCallMng.OperatingSim = simId;
    /* gxf todo RilResult      = */
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request get current calls failed: %d\n", RilResult);
    }
}

/**
 * Initiate voice call ( ATD<dial string>; or AT*DIALE=<dial string>,<service Type>)
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (in) number:  phone number to dial
 * return  void
 */
VOID MMI_Modem_Call_Request_Dial(MMI_MODEM_SIM_ID simId, INT8 * number,
                                 MMI_MODEM_CALL_SERVICE_TYPE ServiceType)
{
    MMI_Modemadp_Call_Dial_t * pMsg;

    pMsg = (MMI_Modemadp_Call_Dial_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Dial_t));

    pMsg->SimId       = simId;
    pMsg->Number      = number;
    pMsg->ServiceType = ServiceType;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_DIAL, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Hang up a specific line (like AT+CHLD=1x)
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (in) index:   Connection index (value of 'x' in CHLD above)
 * return  void
 */
VOID MMI_Modem_Call_Request_Hangup(MMI_MODEM_SIM_ID simId, INT32 index)
{
    UINT8 i;

    for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
        if(index == g_ModemCallMng.CallIndex[i]) {
            break;
        }
    }

    if(i == MODEM_CALL_MAX_CONN) {  //index not found
        printf("%s: buffer hangup\n", __FUNCTION__);
        g_ModemCallMng.BufferHangUp = TRUE;
    } else {
        g_ModemCallMng.BufferHangUp = FALSE;

        MMI_Modemadp_Call_Hangup_t * pMsg;
        pMsg = (MMI_Modemadp_Call_Hangup_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Hangup_t));

        pMsg->SimId = simId;
        pMsg->Index = index;
        UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_HANGUP, (UI_Inter_Msg_t *)pMsg);
    }
}

/**
 * Hang up waiting or held (like AT+CHLD=0)
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Hangup_Waiting_Or_Background(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Hangup_Waiting_Or_Bg_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Hangup_Waiting_Or_Bg_t *)Hal_Mem_Alloc(sizeof(
                    MMI_Modemadp_Call_Hangup_Waiting_Or_Bg_t));

    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_HANGUP_WAITING_OR_BG,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * Hang up active, and resume waiting or held (like AT+CHLD=1)
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Hangup_Foreground_Resume_Background(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Hangup_Fg_Resume_Bg_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Hangup_Fg_Resume_Bg_t *)Hal_Mem_Alloc(sizeof(
                    MMI_Modemadp_Call_Hangup_Fg_Resume_Bg_t));

    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_HANGUP_FG_RESUME_BG,
                      (UI_Inter_Msg_t *)pMsg);
}

/*
 * Switch waiting or holding call and active call (like AT+CHLD=2)
 *
 * State transitions should be is follows:
 *
 * If call 1 is waiting and call 2 is active, then if this re
 *
 *   BEFORE                               AFTER
 * Call 1   Call 2                 Call 1       Call 2
 * ACTIVE   HOLDING                HOLDING     ACTIVE
 * ACTIVE   WAITING                HOLDING     ACTIVE
 * HOLDING  WAITING                HOLDING     ACTIVE
 * ACTIVE   IDLE                   HOLDING     IDLE
 * IDLE     IDLE                   IDLE        IDLE
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Switch_Waiting_Or_Holding_And_Active(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Switch_Waiting_Or_Holding_And_Active_t * pMsg;

    pMsg = (MMI_Modemadp_Call_Switch_Waiting_Or_Holding_And_Active_t *)Hal_Mem_Alloc(
               sizeof(MMI_Modemadp_Call_Switch_Waiting_Or_Holding_And_Active_t));
    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP,
                      MMI_MODEMADP_CALL_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * Conference holding and active (like AT+CHLD=3)
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Conference(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Conf_t * pMsg;

    pMsg        = (MMI_Modemadp_Call_Conf_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Conf_t));
    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_CONF, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Separate a party from a multiparty call placing the multiparty call
 * (less the specified party) on hold and leaving the specified party
 * as the only other member of the current (active) call
 *
 * Like AT+CHLD=2x
 *
 * See TS 22.084 1.3.8.2 (iii)
 * TS 22.030 6.5.5 "Entering "2X followed by send"
 * TS 27.007 "AT+CHLD=2x"
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (in) index:   Connection index (value of 'x' in CHLD above)
 * return  void
 */
VOID MMI_Modem_Call_Request_Separate_Connection(MMI_MODEM_SIM_ID simId, INT32 index)
{
    MMI_Modemadp_Call_Seperate_Conn_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Seperate_Conn_t *)Hal_Mem_Alloc(sizeof(
                    MMI_Modemadp_Call_Seperate_Conn_t));

    pMsg->SimId = simId;
    pMsg->Index = index;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_SEPERATE_CONN,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * Connects the two calls and disconnects the subscriber from both calls (ECT). (AT+CHLD=4)
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Explicit_Call_Transfer(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Ect_t * pMsg;

    pMsg        = (MMI_Modemadp_Call_Ect_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Ect_t));
    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_EXPLICIT_CALL_TRANSFER,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * Send UDUB (user determined user busy) to ringing or
 * waiting call answer  (AT+CHLD=0)
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Udub(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Udub_t * pMsg;

    pMsg        = (MMI_Modemadp_Call_Udub_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Udub_t));
    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_UDUB, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Answer incoming call (ATA)
 *
 * Will not be called for WAITING calls.
 * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE will be used in this case instead
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Answer(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Answer_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Answer_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Answer_t));
    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_ANSWER, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Send a DTMF tone (AT+VTS=<DTMF>)
 *
 * If the implementation is currently playing a tone requested via
 * RIL_REQUEST_DTMF_START, that tone should be cancelled and the new tone
 * should be played instead
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (in) dtmf:  MMI_MODEM_CALL_REQUEST_DTMF *
 * return  void
 */
VOID MMI_Modem_Call_Request_Dtmf(MMI_MODEM_SIM_ID simId, MMI_Modem_Call_Request_Dtmf_t * dtmf)
{
    MMI_Modemadp_Call_Dtmf_t * pMsg;

    pMsg        = (MMI_Modemadp_Call_Dtmf_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Dtmf_t));
    pMsg->SimId = simId;
    pMsg->Dtmf  = dtmf;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_DTMF, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Start playing a DTMF tone. Continue playing DTMF tone until
 * RIL_REQUEST_DTMF_STOP is received (AT+VTS=<DTMF>)
 *
 * If a RIL_REQUEST_DTMF_START is received while a tone is currently playing,
 * it should cancel the previous tone and play the new one.
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (in) dtmf: a single character with one of 12 values: 0-9,*,#
 * return  void
 */
VOID MMI_Modem_Call_Request_Dtmf_Start(MMI_MODEM_SIM_ID simId, INT8 dtmf)
{
    MMI_Modemadp_Call_Dtmf_Start_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Dtmf_Start_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Dtmf_Start_t));
    pMsg->SimId = simId;
    pMsg->Dtmf  = dtmf;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_DTMF_START,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * Stop playing a currently playing DTMF tone. (AT)
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * return  void
 */
VOID MMI_Modem_Call_Request_Dtmf_stop(MMI_MODEM_SIM_ID simId)
{
    MMI_Modemadp_Call_Dtmf_Stop_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Dtmf_Stop_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Dtmf_Stop_t));
    pMsg->SimId = simId;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_DTMF_STOP, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Turn on or off uplink (microphone) mute. ("AT+CMUT=<n>)
 *
 * Will only be sent while voice call is active.
 * Will always be reset to "disable mute" when a new voice call is initiated
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (in) mute:   1 for "enable mute" and 0 for "disable mute"
 * return  void
 */
VOID MMI_Modem_Call_Request_Set_Mute(MMI_MODEM_SIM_ID simId, BOOL mute)
{
    MMI_Modemadp_Call_Set_Mute_t * pMsg;

    pMsg =
        (MMI_Modemadp_Call_Set_Mute_t *)Hal_Mem_Alloc(sizeof(MMI_Modemadp_Call_Set_Mute_t));
    pMsg->SimId = simId;
    pMsg->Mute  = mute;
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, MMI_MODEMADP_CALL_SET_MUTE, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Queries the current state of the uplink mute setting (AT+CMUT?)
 *
 * param (in) simId:  MMI_MODEM_SIM_ID
 * param (out) mute:   1 for "mute enabled" and 0 for "mute disabled"
 * return  void
 */
VOID MMI_Modem_Call_Request_Get_Mute(MMI_MODEM_SIM_ID simId, INT32 * mute)
{
    RIL_Errno RilResult;

    /*gxf todo RilResult = Ril_CC_Request_Get_Mute(MMI_ModemAdp_Get_Ril_SimId(simId), mute); */
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request dtmf stop failed: %d\n", RilResult);
    }
}

/**
 * Indicates whether remote state is hold
 *
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * param state:  1 for hold, and 0 for unhold
 * return  void
 */
extern VOID MMI_Modem_Call_Response_Remote_Hold(MMI_MODEM_SIM_ID SimId, INT32 Index, UINT8 State);

/******************************************************************************
 *
 *         RIL -> Modem Adaptor
 *
 *******************************************************************************/
void Ril_CC_Response_Get_Current_Calls(RIL_CC_REQUEST_GET_CURRENT_CALLS * calls, RIL_Errno result)
{
#if 0
    RIL_Modemadp_Cc_Rsp_Get_Cur_Calls_t * pMsg;

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Get_Cur_Calls_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Get_Cur_Calls_t));

    pMsg->Result  = result;
    pMsg->Calls   = calls;

    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_GET_CUR_CALLS, (UI_Inter_Msg_t *)pMsg);
#endif
}
/**
 *
 * Indicates an incoming call (voice, data or fax) is indicated by the cellular network. (RING)
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_Ring(RIL_SIM_ID SimId, const INT8 * s)
{
    RIL_Modemadp_Cc_Rsp_Ring_t * pMsg;
    UINT16                        RingStringLen;
    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Ring_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Ring_t));
    RingStringLen = strlen(s);

    pMsg->SimId  = SimId;
    pMsg->Ring_s = Hal_Mem_Alloc(RingStringLen + 1);
    strncpy(pMsg->Ring_s, s, RingStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_RING, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Indicates the type of incoming call when receive an incoming call. (+CRING:)
 * +CRING: <type>
 *
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_CRing(RIL_SIM_ID SimId, const INT8 * s)
{
    Ril_CC_Response_Ring(SimId, s);
}

/**
 * Indicates a disconnect call. (+CALLDISCONNECT:)
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const char *
 * return  void
 */
void Ril_CC_Response_Call_Disconnect(RIL_SIM_ID sid, const char * s)
{
    RIL_Modemadp_Cc_Rsp_Call_Disconnect_t * pMsg;
    UINT16                              CallDisconnectStringLen;
    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Call_Disconnect_t *)Hal_Mem_Alloc(sizeof(
                    RIL_Modemadp_Cc_Rsp_Call_Disconnect_t));
    CallDisconnectStringLen = strlen(s);

    pMsg->SimId       = sid;
    pMsg->CallDisconnect_s = Hal_Mem_Alloc(CallDisconnectStringLen + 1);
    strncpy(pMsg->CallDisconnect_s, s, CallDisconnectStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CALL_DISCONNECT,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * Indicates a disconnect for Call Clearing or a Call Failed for an outgoing call. (NO CARRIER)
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_No_Carrier(RIL_SIM_ID SimId, const INT8 * s)
{
    RIL_Modemadp_Cc_Rsp_No_Carrier_t * pMsg;
    UINT16                              NoCarrierStringLen;
    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_No_Carrier_t *)Hal_Mem_Alloc(sizeof(
                    RIL_Modemadp_Cc_Rsp_No_Carrier_t));
    NoCarrierStringLen = strlen(s);

    pMsg->SimId       = SimId;
    pMsg->NoCarrier_s = Hal_Mem_Alloc(NoCarrierStringLen + 1);
    strncpy(pMsg->NoCarrier_s, s, NoCarrierStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_NO_CARRIER,
                      (UI_Inter_Msg_t *)pMsg);
}

/**
 * CONNECT indication.
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_Connect(RIL_SIM_ID SimId, const INT8 * s)
{
#if 0
    RIL_Modemadp_Cc_Rsp_Conn_t * pMsg;
    UINT16                        ConnStringLen;

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Conn_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Conn_t));
    ConnStringLen = strlen(s);

    pMsg->SimId  = SimId;
    pMsg->Conn_s = Hal_Mem_Alloc(ConnStringLen + 1);
    strncpy(pMsg->Conn_s, s, ConnStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CONN, (UI_Inter_Msg_t *)pMsg);
#endif
}

/**
 * Indicates Call Waiting (CW) information (when enabled) for an incoming call. (+CCWA:)
 * +CCWA: <number>,<type>,<class>,[<alpha>][,<CLI validity>[,<subaddr>,<satype>[,<priority>]]]
 *
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_Ccwa(RIL_SIM_ID SimId, const INT8 * s)
{
#if 0   //not supoort call waiting
    RIL_Modemadp_Cc_Rsp_Ccwa_t * pMsg;
    UINT16                        CcwaStringLen;

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Ccwa_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Ccwa_t));
    CcwaStringLen = strlen(s);

    pMsg->SimId      = SimId;
    pMsg->CcwaString = Hal_Mem_Alloc(CcwaStringLen + 1);
    strncpy(pMsg->CcwaString, s, CcwaStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CCWA, (UI_Inter_Msg_t *)pMsg);
#endif
}

/**
 * Presents an indication to list the current call information. (+CLCC:)
 * [+CLCC: <id1>,<dir>,<stat>,<mode>,<mpty>[,<number>,<type>[,<alpha>]]
 * [<CR><LF>+CLCC:<id2>,<dir>,<stat>,<mode>,<mpty>[,<number>,<type>[,<alpha>]]
 * [...]]]
 *
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_Clcc(RIL_SIM_ID SimId, const INT8 * s)
{
    RIL_Modemadp_Cc_Rsp_Clcc_t * pMsg;
    UINT16                        ClccStringLen;
    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Clcc_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Clcc_t));
    ClccStringLen = strlen(s);

    pMsg->SimId      = SimId;
    pMsg->ClccString = Hal_Mem_Alloc(ClccStringLen + 1);
    strncpy(pMsg->ClccString, s, ClccStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CLCC, (UI_Inter_Msg_t *)pMsg);
}

/**
 * Indicates the calling line identity of the calling party after every RING/+CRING. (+CLIP:)
 * +CLIP: <number>,<type>
 *
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_Clip(RIL_SIM_ID SimId, const INT8 * s)
{
#if 0   //handle incoming call when +CLCC is received.
    RIL_Modemadp_Cc_Rsp_Clip_t * pMsg;
    UINT16                        ClipStringLen;

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Clip_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Clip_t));
    ClipStringLen = strlen(s);

    pMsg->SimId  = SimId;
    pMsg->Clip_s = Hal_Mem_Alloc(ClipStringLen + 1);
    strncpy(pMsg->Clip_s, s, ClipStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CLIP, (UI_Inter_Msg_t *)pMsg);
#endif
}

/**
 * Indicates ATD dial result: "OK","CME ERROR"
 * param (in) sid:  RIL_SIM_ID
 * param (in) s:  const INT8 *
 * return  void
 */
VOID Ril_CC_Response_Dial(RIL_SIM_ID SimId, const INT8 * s)
{
    RIL_Modemadp_Cc_Rsp_Dial_t * pMsg;
    UINT16                     RspDialStringLen;
    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Dial_t *)Hal_Mem_Alloc(sizeof(
                    RIL_Modemadp_Cc_Rsp_Dial_t));
    RspDialStringLen = strlen(s);

    pMsg->SimId       = SimId;
    pMsg->RspDial_s = Hal_Mem_Alloc(RspDialStringLen + 1);
    strncpy(pMsg->RspDial_s, s, RspDialStringLen + 1);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_DIAL,
                      (UI_Inter_Msg_t *)pMsg);
}

void Ril_CC_Response_Ceer(RIL_SIM_ID SimId, const char * s)
{
    RIL_Modemadp_Cc_Rsp_Ceer_t * pMsg;
    UINT16                     RspCeerStringLen;
    if(gcf_test) {
        Hal_Mem_Free(s);
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Ceer_t *)Hal_Mem_Alloc(sizeof(
                    RIL_Modemadp_Cc_Rsp_Ceer_t));
    RspCeerStringLen = strlen(s);

    pMsg->SimId       = SimId;
    pMsg->RspCeer_s = Hal_Mem_Alloc(RspCeerStringLen + 1);
    strncpy(pMsg->RspCeer_s, s, RspCeerStringLen + 1);
    Hal_Mem_Free(s);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CEER,
                      (UI_Inter_Msg_t *)pMsg);
}

/******************************************************************************
 *
 *         Message Handler of MMI -> Modem Adaptor
 *
 *******************************************************************************/

/**
 * Handler of CALL DIAL
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Dial_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Errno                        RilResult;
    MMI_Modemadp_Call_Dial_t   *   CallDial;
    RIL_Dial             *            RilDial;

    CallDial                    = (MMI_Modemadp_Call_Dial_t *)Msg;
    g_ModemCallMng.OperatingSim = CallDial->SimId;

    /* (same as 'n' paremeter in TS 27.007 7.7 "+CLIR"
     * clir == 0 on "use subscription default value"
     * clir == 1 on "CLIR invocation" (restrict CLI presentation)
     * clir == 2 on "CLIR suppression" (allow CLI presentation)
     */
    RilDial          = (RIL_Dial *)Hal_Mem_Alloc(sizeof(RIL_Dial));
    RilDial->clir    = 0;
    RilDial->uusInfo = NULL;
    RilDial->address = CallDial->Number;

    RilResult        = Ril_CC_Request_Dial(MMI_ModemAdp_Get_Ril_SimId(CallDial->SimId), RilDial);
    if (RilDial->address) {
        Hal_Mem_Free(RilDial->address);
    }
    Hal_Mem_Free(RilDial);

    if(RIL_E_SUCCESS == RilResult) {
        g_ModemCallMng.GetCurCallsCau = MODEM_CALL_DIAL;
        g_ModemCallMng.RequestDial = TRUE;
    } else {
        MMI_Modem_Call_Response_No_Carrier(CallDial->SimId, MMI_MODEM_CALL_INVALID_INDEX, 0);
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request call dial failed: %d\n", RilResult);
    }
} /* MMI_ModemAdp_Call_Dial_Handler */

/**
 * Handler of MMI_MODEMADP_CALL_HANGUP
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Hangup_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Hangup_t * CallHangupRequest;
    RIL_Errno                     RilResult;

    CallHangupRequest = (MMI_Modemadp_Call_Hangup_t *)Msg;

    RilResult = Ril_CC_Request_Hangup(MMI_ModemAdp_Get_Ril_SimId(
                                          CallHangupRequest->SimId), CallHangupRequest->Index);
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR, "Ril request hangup failed: %d\n",
                   RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_HANGUP_WAITING_OR_BG
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Hangup_Waiting_Or_Bg_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Hangup_Waiting_Or_Bg_t * HangupWaitingOrBgRequest;
    RIL_Errno                                   RilResult;

    HangupWaitingOrBgRequest = (MMI_Modemadp_Call_Hangup_Waiting_Or_Bg_t *)Msg;
    RilResult                = Ril_CC_Request_Hangup_Waiting_Or_Background(MMI_ModemAdp_Get_Ril_SimId(
                                   HangupWaitingOrBgRequest->SimId));
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request call hangup waiting or BG failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_HANGUP_FG_RESUME_BG
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Hangup_Fg_Resume_Bg_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Hangup_Fg_Resume_Bg_t * HangupFgResumeBgRequest;
    RIL_Errno                                  RilResult;

    HangupFgResumeBgRequest = (MMI_Modemadp_Call_Hangup_Fg_Resume_Bg_t *)Msg;
    RilResult               = Ril_CC_Request_Hangup_Foreground_Resume_Background(MMI_ModemAdp_Get_Ril_SimId(
                                  HangupFgResumeBgRequest->SimId));
    g_ModemCallMng.OperatingSim = HangupFgResumeBgRequest->SimId;
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request call hangup FG resume BG failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Switch_WaitingOrHolding_And_Active_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Switch_Waiting_Or_Holding_And_Active_t *
    SwitchWaitingOrHoldingAndActiveRequest;
    RIL_Errno RilResult;

    SwitchWaitingOrHoldingAndActiveRequest =
        (MMI_Modemadp_Call_Switch_Waiting_Or_Holding_And_Active_t *)Msg;
    RilResult = Ril_CC_Request_Switch_Waiting_Or_Holding_And_Active(MMI_ModemAdp_Get_Ril_SimId(
                    SwitchWaitingOrHoldingAndActiveRequest->SimId));
    g_ModemCallMng.OperatingSim = SwitchWaitingOrHoldingAndActiveRequest->SimId;
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request switch waiting or holding and active failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_CONF
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Conference_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Conf_t * CallConfRequest;
    RIL_Errno                   RilResult;

    CallConfRequest = (MMI_Modemadp_Call_Conf_t *)Msg;
    RilResult       =
        Ril_CC_Request_Conference(MMI_ModemAdp_Get_Ril_SimId(CallConfRequest->SimId));
    g_ModemCallMng.OperatingSim = CallConfRequest->SimId;
    if(RIL_E_SUCCESS == RilResult) {
        g_ModemCallMng.DualCallPresent = TRUE;
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request call conference failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_SEPERATE_CONN
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Seperate_Conn_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Seperate_Conn_t * CallSeperateConnRequest;
    RIL_Errno                            RilResult;
    UINT8                                i;

    CallSeperateConnRequest = (MMI_Modemadp_Call_Seperate_Conn_t *)Msg;
    RilResult               =
        Ril_CC_Request_Separate_Connection(MMI_ModemAdp_Get_Ril_SimId(
                CallSeperateConnRequest->SimId), CallSeperateConnRequest->Index);
    g_ModemCallMng.OperatingSim = CallSeperateConnRequest->SimId;
    if(RIL_E_SUCCESS == RilResult) {
        for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
            // find the non-FG call
            if(i != g_ModemCallMng.FgActiveCall) {
                // if the non-FG call is the seperated one, nothing need to do
                if(CallSeperateConnRequest->Index == g_ModemCallMng.CallIndex[i]) {
                    break;
                }
                // if the non-FG call is not the seperated one, means the FG call has been seperated,
                // then set the non-FG call as the FG call
                else {
                    // set the non-FG as FG
                    g_ModemCallMng.FgActiveCall = i;
                    break;
                }
            }
        }
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request seperate connection failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_EXPLICIT_CALL_TRANSFER
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Explicit_Call_Transfer_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Ect_t * CallEctRequest;
    RIL_Errno                  RilResult;

    CallEctRequest = (MMI_Modemadp_Call_Ect_t *)Msg;
    RilResult      =
        Ril_CC_Request_Explicit_Call_Transfer(MMI_ModemAdp_Get_Ril_SimId(CallEctRequest->SimId));
    g_ModemCallMng.OperatingSim = CallEctRequest->SimId;
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR, "Ril request ECT failed: %d\n",
                   RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_UDUB
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Udub_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Udub_t * CallUdubRequest;
    RIL_Errno                   RilResult;

    CallUdubRequest = (MMI_Modemadp_Call_Udub_t *)Msg;
    RilResult       = Ril_CC_Request_Udub(MMI_ModemAdp_Get_Ril_SimId(CallUdubRequest->SimId));
    if(RIL_E_SUCCESS != RilResult) {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR, "Ril request udub failed: %d\n",
                   RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_ANSWER
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Answer_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Answer_t * CallAnswer;
    RIL_Errno                     RilResult;
    UINT8                         i;

    CallAnswer = (MMI_Modemadp_Call_Answer_t *)Msg;
    RilResult  = Ril_CC_Request_Answer(MMI_ModemAdp_Get_Ril_SimId(
                                           CallAnswer->SimId));
    g_ModemCallMng.OperatingSim = CallAnswer->SimId;
    if(RIL_E_SUCCESS == RilResult) {
        // when ATA is used, there should be only one call
        for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
            if(MMI_MODEM_CALL_INVALID_INDEX != g_ModemCallMng.CallIndex[i]) {
                g_ModemCallMng.FgActiveCall = i;
                break;
            }
        }
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request answer call failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_DTMF
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Dtmf_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Dtmf_t * CallDtmfRequest;
    RIL_Errno                   RilResult;

    CallDtmfRequest = (MMI_Modemadp_Call_Dtmf_t *)Msg;
    RilResult       =
        Ril_CC_Request_Dtmf(MMI_ModemAdp_Get_Ril_SimId(CallDtmfRequest->SimId),
                            (RIL_CC_REQUEST_DTMF *)(CallDtmfRequest->Dtmf));
    Hal_Mem_Free(CallDtmfRequest->Dtmf);
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR, "Ril request dtmf failed: %d\n",
                   RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_DTMF_START
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Dtmf_Start_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Dtmf_Start_t * CallDtmfStartRequest;
    RIL_Errno                         RilResult;

    CallDtmfStartRequest = (MMI_Modemadp_Call_Dtmf_Start_t *)Msg;
    RilResult            =
        Ril_CC_Request_Dtmf_Start(MMI_ModemAdp_Get_Ril_SimId(
                                      CallDtmfStartRequest->SimId), CallDtmfStartRequest->Dtmf);
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request dtmf start failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_DTMF_STOP
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Dtmf_Stop_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Dtmf_Stop_t * CallDtmfStopRequest;
    RIL_Errno                        RilResult;

    CallDtmfStopRequest = (MMI_Modemadp_Call_Dtmf_Stop_t *)Msg;
    RilResult           =
        Ril_CC_Request_Dtmf_stop(MMI_ModemAdp_Get_Ril_SimId(CallDtmfStopRequest->SimId));
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request dtmf stop failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_SET_MUTE
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Set_Mute_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Set_Mute_t * CallSetMuteRequest;
    RIL_Errno                       RilResult;

    CallSetMuteRequest = (MMI_Modemadp_Call_Set_Mute_t *)Msg;
    RilResult          =
        Ril_CC_Request_Set_Mute(MMI_ModemAdp_Get_Ril_SimId(
                                    CallSetMuteRequest->SimId), CallSetMuteRequest->Mute);
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request dtmf stop failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_REQUEST_IMEI
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Request_Imei_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Request_Imei_t * CallImeiRequest;
    RIL_Errno                       RilResult;

    CallImeiRequest = (MMI_Modemadp_Call_Request_Imei_t *)Msg;

    RilResult   = Ril_DEV_Request_Get_Imei(MMI_ModemAdp_Get_Ril_SimId(CallImeiRequest->SimId));
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request IMEI failed: %d\n", RilResult);
    }
}

/**
 * Handler of MMI_MODEMADP_CALL_REQUEST_BASEBAND_VERSION
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Call_Request_Baseband_Version_Handler(UI_Inter_Msg_t * Msg)
{
    MMI_Modemadp_Call_Request_Baseband_Version_t * CallBasebandVerRequest;
    RIL_Errno                       RilResult;

    CallBasebandVerRequest = (MMI_Modemadp_Call_Request_Baseband_Version_t *)Msg;

    RilResult   = Ril_DEV_Request_Baseband_Version(MMI_ModemAdp_Get_Ril_SimId(CallBasebandVerRequest->SimId));
    if(RIL_E_SUCCESS == RilResult) {
        // nothing to do
    } else {
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril request Baseband Version failed: %d\n", RilResult);
    }
}

/******************************************************************************
 *
 *         Message Handler of RIL -> Modem Adaptor
 *
 *******************************************************************************/

/**
 * Handler of RIL_CC_RSP_CLCC
 * [+CLCC: <id1>,<dir>,<stat>,<mode>,<mpty>[,<number>,<type>[,<alpha>]]
 * [<CR><LF>+CLCC:<id2>,<dir>,<stat>,<mode>,<mpty>[,<number>,<type>[,<alpha>]]
 * [...]]]
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Clcc_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Clcc_t     *     CcRspClcc;
    MMI_Modem_Call_Response_State_Change_t * StateChg;
    MMI_Modem_Call_Response_Clip_t * Clip;
    MMI_Modem_Call_Response_Ccwa_t *Ccwa;
    UINT16                                 ClccStringLen;
    UINT16                                 i, j, k;
    UINT8                                  CallCnt = 0;
    UINT8                                  FirstEmptyIndex = 0;

    CcRspClcc     = (RIL_Modemadp_Cc_Rsp_Clcc_t *)Msg;
    ClccStringLen = strlen(CcRspClcc->ClccString);

    printf("%s: %s, len=%d\n", __func__, CcRspClcc->ClccString, ClccStringLen);

    // search +CLCC string to get the call count
    for(i = 0; i < ClccStringLen; i++) {
        if(CcRspClcc->ClccString[i] == ':') {
            CallCnt++;
        }
    }

    // prepare the data buffer sent to call
    StateChg =
        (MMI_Modem_Call_Response_State_Change_t *)Hal_Mem_Alloc(sizeof(
                    MMI_Modem_Call_Response_State_Change_t));

    StateChg->calls = (MMI_Modem_Call_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_t) * CallCnt);
    memset(StateChg->calls, 0, sizeof(MMI_Modem_Call_t) * CallCnt);
    StateChg->count = CallCnt;

    i = 0;
    for(k = 0; k < CallCnt; k++) {
        StateChg->calls[k].simId = MMI_ModemAdp_Get_UI_SimId(CcRspClcc->SimId);
        // find the <id1> postion
        for(; i < ClccStringLen; i++) {
            if(CcRspClcc->ClccString[i] == ':') {
                break;
            }
        }
        i++;

        for(j = i; j < ClccStringLen; j++) {
            if(CcRspClcc->ClccString[j] != ' ') {
                break;
            }
        }

        // get <idx1> value
        StateChg->calls[k].index = 0;
        for(i = j; i < ClccStringLen; i++) {
            if(CcRspClcc->ClccString[i] != ',') {
                StateChg->calls[k].index *= 10;
                StateChg->calls[k].index += CcRspClcc->ClccString[i] - 0x30;
            } else {
                break;
            }
        }
        i++;

        for(j = i; j < ClccStringLen; j++) {
            if(CcRspClcc->ClccString[j] != ' ') {
                i = j;
                break;
            }
        }
        // get <dir>: 0 mobile originated (MO) call, 1 mobile terminated (MT) call
        StateChg->calls[k].isMT = CcRspClcc->ClccString[i] - 0x30;
        i += 2;

        for(j = i; j < ClccStringLen; j++) {
            if(CcRspClcc->ClccString[j] != ' ') {
                i = j;
                break;
            }
        }
        // get <stat>
        /* <stat> (state of the call):
         *  0 active
         *  1 held
         *  2 dialing (MO call)
         *  3 alerting (MO call)
         *  4 incoming (MT call)
         *  5 waiting (MT call)
         *  6 offering(MT call)
         */
        StateChg->calls[k].state = MMI_ModemAdp_Get_UI_Call_State((RIL_CallState)(CcRspClcc->ClccString[i] - 0x30));
        i += 2;

        for(j = i; j < ClccStringLen; j++) {
            if(CcRspClcc->ClccString[j] != ' ') {
                i = j;
                break;
            }
        }

        // get <mode>
        /*    <mode> (bearer/teleservice):
         *      0 voice
         *      1 data
         *      2 fax
         *      3 voice followed by data, voice mode
         *      4 alternating voice/data, voice mode
         *      5 alternating voice/fax, voice mode
         *      6 voice followed by data, data mode
         *      7 alternating voice/data, data mode
         *      8 alternating voice/fax, fax mode
         *      9 unknown
         */
        StateChg->calls[k].isVoice = CcRspClcc->ClccString[i] - 0x30;
        if((0 == StateChg->calls[k].isVoice) || (3 == StateChg->calls[k].isVoice)
                || (4 == StateChg->calls[k].isVoice) || (5 == StateChg->calls[k].isVoice)) {
            StateChg->calls[k].isVoice = 1;
        }
        i += 2;

        for(j = i; j < ClccStringLen; j++) {
            if(CcRspClcc->ClccString[j] != ' ') {
                i = j;
                break;
            }
        }
        // get <mpty>
        /*    0 call is not one of multiparty (conference) call parties
         *    1 call is one of multiparty (conference) call parties
         */
        StateChg->calls[k].isMpty = CcRspClcc->ClccString[i] - 0x30;
        i += 2;

        for(j = i; j < ClccStringLen; j++) {
            if(CcRspClcc->ClccString[j] != ' ') {
                i = j;
                break;
            }
        }
        i++;    //skip " before number

        // get <number> & <type>
        if(i < ClccStringLen) {
            // get <number>
            j = 0;
            StateChg->calls[k].number = Hal_Mem_Alloc(MMI_MODEM_MAX_NUMBER_LEN);
            memset(StateChg->calls[k].number, 0, MMI_MODEM_MAX_NUMBER_LEN);
            for(; i < ClccStringLen; i++) {
                if(CcRspClcc->ClccString[i] != '"') {
                    StateChg->calls[k].number[j++] = CcRspClcc->ClccString[i];
                } else {
                    break;
                }
            }
            i += 2;

            for(j = i; j < ClccStringLen; j++) {
                if(CcRspClcc->ClccString[j] != ' ') {
                    i = j;
                    break;
                }
            }

            // get <type>
            /* 24.008, 10.5.4.7, bit8 = 1
             * Type of number
             *  Bits
             *  7 6 5
             *  0 0 0  unknown
             *  0 0 1  international number
             *  0 1 0  national number
             *  0 1 1  network specific number (Note 4)
             *  1 0 0  dedicated access, short code
             *  1 0 1  reserved
             *  1 1 0  reserved
             *  1 1 1  reserved for extension
             *
             * Numbering plan identification
             * Number plan (applies for type of number = 000, 001, 010 and 100)
             *  Bits
             *  4 3 2 1
             *  0 0 0 0 unknown
             *  0 0 0 1 ISDN/telephony numbering plan (ITU-T Rec. E.164 [45] / ITU-
             *  T Rec. E.163 [44])
             *  0 0 1 1 data numbering plan (ITU-T Rec. X.121 [69])
             *  0 1 0 0 telex numbering plan (ITU-T Rec. F.69 [47])
             *  1 0 0 0 national numbering plan
             *  1 0 0 1 private numbering plan
             *  1 0 1 1 reserved for CTS (see 3GPP TS 44.056 [91])
             *  1 1 1 1 reserved for extension
             */
            StateChg->calls[k].toa = 0;
            for(; i < ClccStringLen; i++) {
                if(CcRspClcc->ClccString[i] != ',') {
                    StateChg->calls[k].toa *= 10;
                    StateChg->calls[k].toa += CcRspClcc->ClccString[i] - 0x30;
                } else {
                    break;
                }
            }
            i++;

            for(j = i; j < ClccStringLen; j++) {
                if(CcRspClcc->ClccString[j] != ' ') {
                    i = j;
                    break;
                }
            }
            i++;    //skip "  before alpha

            // get <alpha>
            if(i < ClccStringLen) {
                StateChg->calls[k].name = Hal_Mem_Alloc(MMI_MODEM_MAX_NAME_LEN);
                memset(StateChg->calls[k].name, 0, MMI_MODEM_MAX_NAME_LEN);
                j = 0;
                for(; i < ClccStringLen; i++) {
                    if(CcRspClcc->ClccString[i] != '"') {
                        StateChg->calls[k].name[j++] = CcRspClcc->ClccString[i];
                    } else {
                        break;
                    }
                }
            }
        }

        switch(StateChg->calls[k].state) {
            case MMI_MODEM_CALL_STATE_DIALING:
                if(FALSE == g_ModemCallMng.RequestDial) {
                    printf("%s: ignore this msg, state=%d.\n", __FUNCTION__, StateChg->calls[k].state);
                    break;
                }

                for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                    // if it's an old call
                    if(StateChg->calls[k].index == g_ModemCallMng.CallIndex[j]) {
                        break;
                    }
                }

                // find the latest new call
                if(j == MODEM_CALL_MAX_CONN) {
                    // find a empty position in CallIndex array for the new call
                    for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                        if(MMI_MODEM_CALL_INVALID_INDEX == g_ModemCallMng.CallIndex[j]) {
                            FirstEmptyIndex = j;
                            break;
                        }
                    }

                    g_ModemCallMng.CallIndex[FirstEmptyIndex] = StateChg->calls[k].index;
                    g_ModemCallMng.FgActiveCall               = FirstEmptyIndex;

                    MMI_Modem_Call_Response_Originating(MMI_ModemAdp_Get_UI_SimId(
                                                            CcRspClcc->SimId), StateChg->calls[k].index);
                }

                if(TRUE == g_ModemCallMng.BufferHangUp) {
                    printf("%s: deal with buffered hangup, state=%d\n", __FUNCTION__, StateChg->calls[k].state);
                    MMI_Modem_Call_Request_Hangup(MMI_ModemAdp_Get_UI_SimId(
                                                      CcRspClcc->SimId), StateChg->calls[k].index);
                    g_ModemCallMng.BufferHangUp = FALSE;
                }

                break;

            case MMI_MODEM_CALL_STATE_ALERTING:
                if(FALSE == g_ModemCallMng.RequestDial) {
                    printf("%s: ignore this msg, state=%d.\n", __FUNCTION__, StateChg->calls[k].state);
                    break;
                }

                MMI_Modem_Call_Response_Alerting(MMI_ModemAdp_Get_UI_SimId(
                                                     CcRspClcc->SimId), StateChg->calls[k].index);

                if(TRUE == g_ModemCallMng.BufferHangUp) {
                    printf("%s: deal with buffered hangup, state=%d\n", __FUNCTION__, StateChg->calls[k].state);
                    MMI_Modem_Call_Request_Hangup(MMI_ModemAdp_Get_UI_SimId(
                                                      CcRspClcc->SimId), StateChg->calls[k].index);
                    g_ModemCallMng.BufferHangUp = FALSE;
                }

                break;

            case MMI_MODEM_CALL_STATE_INCOMING:
                for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                    // if it's an old call
                    if(StateChg->calls[k].index == g_ModemCallMng.CallIndex[j]) {
                        break;
                    }
                }

                // find the latest new call
                if(j == MODEM_CALL_MAX_CONN) {
                    // find a empty position in CallIndex array for the new call
                    for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                        if(MMI_MODEM_CALL_INVALID_INDEX == g_ModemCallMng.CallIndex[j]) {
                            FirstEmptyIndex = j;
                            break;
                        }
                    }

                    g_ModemCallMng.CallIndex[FirstEmptyIndex] = StateChg->calls[k].index;
                    g_ModemCallMng.FgActiveCall               = FirstEmptyIndex;

                    Clip = (MMI_Modem_Call_Response_Clip_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Response_Clip_t));
                    Clip->type = StateChg->calls[k].toa;
                    Clip->number = (char *)Hal_Mem_Alloc(strlen(StateChg->calls[k].number) + 1);
                    strncpy(Clip->number, StateChg->calls[k].number, strlen(StateChg->calls[k].number) + 1);

                    MMI_Modem_Call_Response_Clip(MMI_ModemAdp_Get_UI_SimId(
                                                     CcRspClcc->SimId), StateChg->calls[k].index, Clip);
                }
                break;

            case MMI_MODEM_CALL_STATE_ACTIVE:
                if((FALSE == g_ModemCallMng.RequestDial) && (0 == StateChg->calls[k].isMT)) {
                    printf("%s: ignore this msg, state=%d.\n", __FUNCTION__, StateChg->calls[k].state);
                    break;
                }

                MMI_Modem_Call_Response_Connect(MMI_ModemAdp_Get_UI_SimId(
                                                    CcRspClcc->SimId), StateChg->calls[k].index);
                break;

            case MMI_MODEM_CALL_STATE_WAITING:
                g_ModemCallMng.Ccwa = TRUE;
                //MMI_Modem_Call_Request_Udub(MMI_ModemAdp_Get_UI_SimId(CcRspClcc->SimId));

                Ccwa = (MMI_Modem_Call_Response_Ccwa_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Response_Ccwa_t));
                Ccwa->type = StateChg->calls[k].toa;
                Ccwa->number = (char *)Hal_Mem_Alloc(strlen(StateChg->calls[k].number) + 1);
                memset(Ccwa->number,0,strlen(StateChg->calls[k].number) + 1);
                memcpy(Ccwa->number,StateChg->calls[k].number,strlen(StateChg->calls[k].number));
                Ccwa->class = 1;
                MMI_Modem_Call_Response_Ccwa(MMI_ModemAdp_Get_UI_SimId(
                                                CcRspClcc->SimId), StateChg->calls[k].index, Ccwa);
                break;

            case MMI_MODEM_CALL_STATE_INVALID:  // if receive DISCONNECT from the peer side during a call
                break;

            default:
                break;
        }
        g_ModemCallMng.CallConnIndex = StateChg->calls[k].index;
        printf("%s: index=%d, isMT=%d, state=%d, isVoice=%d, isMpty=%d, number=%s, type=%d, name=%s\n",
               __func__,
               StateChg->calls[k].index,
               StateChg->calls[k].isMT,
               StateChg->calls[k].state,
               StateChg->calls[k].isVoice,
               StateChg->calls[k].isMpty,
               StateChg->calls[k].number,
               StateChg->calls[k].toa,
               StateChg->calls[k].name
              );
    }

    Hal_Mem_Free(CcRspClcc->ClccString);

    MMI_Modem_Call_Response_State_Change(StateChg);
} /* MMI_ModemAdp_Ril_CC_Rsp_Clcc_Handler */

/**
 * Handler of RIL_CC_RSP_CCWA
 * +CCWA: <number>,<type>,<class>,[<alpha>][,<CLI validity>[,<subaddr>,<satype>[,<priority>]]]
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Ccwa_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Errno                        RilResult;

    RIL_Modemadp_Cc_Rsp_Ccwa_t  *  CcRspCcwa;
    MMI_Modem_Call_Response_Ccwa_t  * CcwaInfo;
    UINT16                           CcwaStringLen;
    UINT16                           i, j, k;

    CcRspCcwa     = (RIL_Modemadp_Cc_Rsp_Ccwa_t *)Msg;
    CcwaStringLen = strlen(CcRspCcwa->CcwaString);

    CcwaInfo = (MMI_Modem_Call_Response_Ccwa_t *)Hal_Mem_Alloc(
                   sizeof(MMI_Modem_Call_Response_Ccwa_t));
    g_ModemCallMng.CcwaInfo = CcwaInfo;

    // find the <number> postion
    for(i = 0; i < CcwaStringLen; i++) {
        if(CcRspCcwa->CcwaString[i] == ':') {
            break;
        }
    }
    for(j = i; j < CcwaStringLen; j++) {
        if(CcRspCcwa->CcwaString[j] != ' ') {
            break;
        }
    }

    // get <number> value
    CcwaInfo->number = Hal_Mem_Alloc(MMI_MODEM_MAX_NUMBER_LEN);
    k                = 0;
    for(i = j; i < CcwaStringLen; i++) {
        if((CcRspCcwa->CcwaString[i] != ',') && (k < MMI_MODEM_MAX_NUMBER_LEN)) {
            CcwaInfo->number[k++] = CcRspCcwa->CcwaString[i];
        } else {
            break;
        }
    }
    // in case of ccwa number length longer than the storing array
    if(k == MMI_MODEM_MAX_NUMBER_LEN) {
        for(; i < CcwaStringLen; i++) {
            if(CcRspCcwa->CcwaString[i] != ',') {
                continue;
            } else {
                break;
            }
        }
    }
    i++;

    // get <type>:
    /* 24.008, 10.5.4.7, bit8 = 1
     * Type of number
     *  Bits
     *  7 6 5
     *  0 0 0  unknown
     *  0 0 1  international number
     *  0 1 0  national number
     *  0 1 1  network specific number (Note 4)
     *  1 0 0  dedicated access, short code
     *  1 0 1  reserved
     *  1 1 0  reserved
     *  1 1 1  reserved for extension
     *
     * Numbering plan identification
     * Number plan (applies for type of number = 000, 001, 010 and 100)
     *  Bits
     *  4 3 2 1
     *  0 0 0 0 unknown
     *  0 0 0 1 ISDN/telephony numbering plan (ITU-T Rec. E.164 [45] / ITU-
     *  T Rec. E.163 [44])
     *  0 0 1 1 data numbering plan (ITU-T Rec. X.121 [69])
     *  0 1 0 0 telex numbering plan (ITU-T Rec. F.69 [47])
     *  1 0 0 0 national numbering plan
     *  1 0 0 1 private numbering plan
     *  1 0 1 1 reserved for CTS (see 3GPP TS 44.056 [91])
     *  1 1 1 1 reserved for extension
     */
    CcwaInfo->type = 0;
    for(; i < CcwaStringLen; i++) {
        if(CcRspCcwa->CcwaString[i] != ',') {
            CcwaInfo->type *= 10;
            CcwaInfo->type += CcRspCcwa->CcwaString[i] - 0x30;
        } else {
            break;
        }
    }
    i++;

    // get <class>
    /* <class> is a sum of integers each representing a class of information (default 7):
     *  1: voice (telephony)
     *  2: data (refers to all bearer services; with <mode>=2 this may refer only to some bearer
     *     service if TA does not support values 16, 32, 64 and 128)
     *  4: fax (facsimile services)
     *  8: short message service
     *  16: data circuit sync
     *  32: data circuit async
     *  64: dedicated packet access
     *  128: dedicated PAD access
     */
    CcwaInfo->class = 0;
    for(; i < CcwaStringLen; i++) {
        if(CcRspCcwa->CcwaString[i] != ',') {
            CcwaInfo->class *= 10;
            CcwaInfo->class += CcRspCcwa->CcwaString[i] - 0x30;
        } else {
            break;
        }
    }

    // to gxf RilResult                   = Ril_CC_Request_Get_Current_Calls(CcRspCcwa->SimId, &RilCalls);
    RilResult                   = Ril_CC_Request_Get_Current_Calls(CcRspCcwa->SimId);
    g_ModemCallMng.GetCurCallsCau = MODEM_RSP_CCWA;
    g_ModemCallMng.OperatingSim = MMI_ModemAdp_Get_UI_SimId(CcRspCcwa->SimId);
    if(RIL_E_SUCCESS != RilResult) {
        Hal_Mem_Free(CcwaInfo->number);
        Hal_Mem_Free(CcwaInfo);
        g_ModemCallMng.CcwaInfo = NULL;
        UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                   "Ril rquest get current calls failed on ccwa: %d\n", RilResult);
    }
} /* MMI_ModemAdp_Ril_CC_Rsp_Ccwa_Handler */

/**
 * Handler of RIL_MODEMADP_CC_RSP_GET_CUR_CALLS
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Get_Cur_Calls_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Get_Cur_Calls_t * GetCurCalls;
    MMI_Modem_Call_Rsp_Get_Current_Calls_t * calls;
    RIL_CC_REQUEST_GET_CURRENT_CALLS RilCalls;
    UINT8                            i, j;
    UINT8                            FirstEmptyIndex = 0;

    // find a empty position in CallIndex array for the waiting call
    for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
        if(MMI_MODEM_CALL_INVALID_INDEX == g_ModemCallMng.CallIndex[i]) {
            FirstEmptyIndex = i;
            break;
        }
    }

    GetCurCalls = (RIL_Modemadp_Cc_Rsp_Get_Cur_Calls_t *)Msg;
    RilCalls.calls = GetCurCalls->Calls->calls;
    RilCalls.count = GetCurCalls->Calls->count;

    printf("%s: calls=%p, count=%d, result=%d, cause=%d\n",
           __func__,
           GetCurCalls->Calls->calls,
           GetCurCalls->Calls->count,
           GetCurCalls->Result,
           g_ModemCallMng.GetCurCallsCau
          );

    switch(g_ModemCallMng.GetCurCallsCau) {
        case MODEM_GET_CUR_CALLS_RES:
            if(RIL_E_SUCCESS == GetCurCalls->Result) {
                calls = (MMI_Modem_Call_Rsp_Get_Current_Calls_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Rsp_Get_Current_Calls_t));
                calls->count = RilCalls.count;
                calls->calls = (MMI_Modem_Call_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_t) * calls->count);
                Hal_Mem_Set(calls->calls, 0, sizeof(MMI_Modem_Call_t) * calls->count);
                for(i = 0; i < RilCalls.count; i++) {
                    calls->calls[i].simId              = g_ModemCallMng.OperatingSim;
                    calls->calls[i].state              = MMI_ModemAdp_Get_UI_Call_State(RilCalls.calls[i].state);
                    calls->calls[i].index              = RilCalls.calls[i].index;
                    calls->calls[i].toa                = RilCalls.calls[i].toa;
                    calls->calls[i].isMpty             = RilCalls.calls[i].isMpty;
                    calls->calls[i].isMT               = RilCalls.calls[i].isMT;
                    calls->calls[i].als                = RilCalls.calls[i].als;
                    calls->calls[i].isVoice            = RilCalls.calls[i].isVoice;
                    calls->calls[i].isVoicePrivacy     = RilCalls.calls[i].isVoicePrivacy;
                    calls->calls[i].numberPresentation = RilCalls.calls[i].numberPresentation;
                    calls->calls[i].namePresentation   = RilCalls.calls[i].namePresentation;

                    if(NULL != RilCalls.calls[i].number) {
                        calls->calls[i].number = (char *)Hal_Mem_Alloc(strlen(RilCalls.calls[i].number) + 1);
                        Hal_Mem_Set(calls->calls[i].number, 0, strlen(RilCalls.calls[i].number) + 1);
                        strncpy(calls->calls[i].number, RilCalls.calls[i].number, strlen(RilCalls.calls[i].number));
                    }
                    if(NULL != RilCalls.calls[i].name) {
                        calls->calls[i].name = (char *)Hal_Mem_Alloc(strlen(RilCalls.calls[i].name) + 1);
                        Hal_Mem_Set(calls->calls[i].name, 0, strlen(RilCalls.calls[i].name) + 1);
                        strncpy(calls->calls[i].name, RilCalls.calls[i].name, strlen(RilCalls.calls[i].name));
                    }
                }
                MMI_Modem_Call_Rsp_Get_Current_Calls(calls);
            } else {
                UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                           "Ril request get current calls failed on MODEM_GET_CUR_CALLS_RES: %d\n",
                           GetCurCalls->Result);
            }
            break;

        case MODEM_CALL_DIAL:
            if(RIL_E_SUCCESS == GetCurCalls->Result) {
                // search the CLCC results to find the latest new call
                for(i = 0; i < RilCalls.count; i++) {
                    for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                        // if it's an old call
                        if(RilCalls.calls[i].index == g_ModemCallMng.CallIndex[j]) {
                            break;
                        }
                    }
                    // find the latest new call
                    if(j == MODEM_CALL_MAX_CONN) {
                        g_ModemCallMng.CallIndex[FirstEmptyIndex] = RilCalls.calls[i].index;
                        g_ModemCallMng.FgActiveCall               = FirstEmptyIndex;
                        MMI_Modem_Call_Response_Originating(g_ModemCallMng.OperatingSim,
                                                            g_ModemCallMng.CallIndex[FirstEmptyIndex]);
                        break;
                    }
                }
                if(RilCalls.count > 1) {
                    g_ModemCallMng.DualCallPresent = TRUE;
                }
            } else {
                UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                           "Ril request get current calls failed on MODEM_CALL_DIAL: %d\n",
                           GetCurCalls->Result);
            }
            break;

        case MODEM_RSP_CCWA:
            if(RIL_E_SUCCESS == GetCurCalls->Result) {
                // search the CLCC results to find the latest new call
                for(i = 0; i < RilCalls.count; i++) {
                    for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                        // if it's an old call
                        if(RilCalls.calls[i].index == g_ModemCallMng.CallIndex[j]) {
                            break;
                        }
                    }
                    // find the latest new call
                    if(j == MODEM_CALL_MAX_CONN) {
                        g_ModemCallMng.CallIndex[FirstEmptyIndex] = RilCalls.calls[i].index;
                        MMI_Modem_Call_Response_Ccwa(g_ModemCallMng.OperatingSim,
                                                     g_ModemCallMng.CallIndex[FirstEmptyIndex],
                                                     g_ModemCallMng.CcwaInfo);
                        if(RilCalls.count > 1) {
                            g_ModemCallMng.DualCallPresent = TRUE;
                        } else if(RilCalls.count == 1) {
                            g_ModemCallMng.FgActiveCall = g_ModemCallMng.CallIndex[FirstEmptyIndex];
                        }
                        break;
                    }
                }

                // in case of failed to find the call index of waiting call
                if(i == RilCalls.count) {
                    Hal_Mem_Free(g_ModemCallMng.CcwaInfo->number);
                    Hal_Mem_Free(g_ModemCallMng.CcwaInfo);
                }
            } else {
                Hal_Mem_Free(g_ModemCallMng.CcwaInfo->number);
                Hal_Mem_Free(g_ModemCallMng.CcwaInfo);
                UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                           "Ril rquest get current calls failed on MODEM_RSP_CCWA: %d\n", GetCurCalls->Result);
            }
            break;

        case MODEM_RSP_RING:
            if(RIL_E_SUCCESS == GetCurCalls->Result) {
                // search the CLCC results to find the latest new call
                for(i = 0; i < RilCalls.count; i++) {
                    for(j = 0; j < MODEM_CALL_MAX_CONN; j++) {
                        // if it's an old call
                        if(RilCalls.calls[i].index == g_ModemCallMng.CallIndex[j]) {
                            break;
                        }
                    }
                    // find the latest new call
                    if(j == MODEM_CALL_MAX_CONN) {
                        g_ModemCallMng.CallIndex[FirstEmptyIndex] = RilCalls.calls[i].index;
                        MMI_Modem_Call_Response_Ring(g_ModemCallMng.OperatingSim,
                                                     g_ModemCallMng.CallIndex[FirstEmptyIndex]);
                        break;
                    }
                }

                if(RilCalls.count > 1) {
                    g_ModemCallMng.DualCallPresent = TRUE;
                }
            } else {
                UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                           "Ril request get current calls failed on MODEM_RSP_RING: %d\n", GetCurCalls->Result);
            }
            Hal_Mem_Free(RilCalls.calls);
            break;

        default:
            UI_Log_Out(UI_SUB_MODULE_MODEM_ADP, UI_LOG_LEVEL_ERROR,
                       "get current calls cause is wrong\n");
            break;
    }
    g_ModemCallMng.GetCurCallsCau = MODEM_GET_CUR_CALL_INV;

    // free the paramter
    if(RilCalls.count > 0) {
        for(i = 0; i < RilCalls.count; i++) {
            if(NULL != RilCalls.calls[i].number) {
                Hal_Mem_Free(RilCalls.calls[i].number);
            }
            if(NULL != RilCalls.calls[i].name) {
                Hal_Mem_Free(RilCalls.calls[i].name);
            }
            if(NULL != RilCalls.calls[i].uusInfo) {
                if(NULL != RilCalls.calls[i].uusInfo->uusData) {
                    Hal_Mem_Free(RilCalls.calls[i].uusInfo->uusData);
                }
                Hal_Mem_Free(RilCalls.calls[i].uusInfo);
            }
        }
        Hal_Mem_Free(RilCalls.calls);
    }
    Hal_Mem_Free(GetCurCalls->Calls);
} /* MMI_ModemAdp_Ril_CC_Rsp_Ring_Handler */

/**
 * Handler of RIL_MODEMADP_CC_RSP_RING
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Ring_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Ring_t  *  CcRspRing;
    CcRspRing = (RIL_Modemadp_Cc_Rsp_Ring_t *)Msg;

    g_ModemCallMng.GetCurCallsCau = MODEM_RSP_RING;
    g_ModemCallMng.OperatingSim = MMI_ModemAdp_Get_UI_SimId(CcRspRing->SimId);

    MMI_Modem_Call_Response_Ring(g_ModemCallMng.OperatingSim, MMI_MODEM_CALL_INVALID_INDEX);

    Hal_Mem_Free(CcRspRing->Ring_s);
} /* MMI_ModemAdp_Ril_CC_Rsp_Ring_Handler */

/**
 * Handler of RIL_MODEMADP_CC_RSP_CALL_DISCONNECT
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Call_Disconnect_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Call_Disconnect_t * CcRspCallDisconnect;
    UINT8                               i;
    UINT8                               DisconnectIndex = 0;

    CcRspCallDisconnect = (RIL_Modemadp_Cc_Rsp_Call_Disconnect_t *)Msg;
    printf("%s: CallDisconnect_s=%s\n", __FUNCTION__, CcRspCallDisconnect->CallDisconnect_s);

    for (i = 0; i < strlen(CcRspCallDisconnect->CallDisconnect_s); i++) {
        if(':' == CcRspCallDisconnect->CallDisconnect_s[i])
        {
            i++;
            break;
        }
    }
    char temp[2];
    memset(temp,0,2);
    strncpy(temp,&(CcRspCallDisconnect->CallDisconnect_s[i+1]),1);
    printf("%s:DisconnectIndex is %s\n",__FUNCTION__,temp);
    if(0 == strncmp(temp,"1",1)) {
        DisconnectIndex = 1;
        printf("%s:DisconnectIndex num is %d\n",__FUNCTION__,DisconnectIndex);
    } else if(0 == strncmp(temp,"2",1)) {
        DisconnectIndex = 2;
        printf("%s:DisconnectIndex num is %d\n",__FUNCTION__,DisconnectIndex);
    } else {
        printf("%s:wrong DisconnectIndex is %s\n",__FUNCTION__,&(CcRspCallDisconnect->CallDisconnect_s[i]));
    }
    if ((1 == DisconnectIndex)||(2 == DisconnectIndex))
    {
        printf("%s:DisconnectIndex numall is %d\n",__FUNCTION__,DisconnectIndex);
        MMI_Modem_Call_Response_Disconnect(MMI_ModemAdp_Get_UI_SimId(CcRspCallDisconnect->SimId), DisconnectIndex);
    }

    Hal_Mem_Free(CcRspCallDisconnect->CallDisconnect_s);
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_NO_CARRIER
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_No_Carrier_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_No_Carrier_t * CcRspNoCarrier;
    UINT8                               i;
    UINT8                               IsNoCarrier;

    CcRspNoCarrier = (RIL_Modemadp_Cc_Rsp_No_Carrier_t *)Msg;
    printf("%s: NoCarrier_s=%s\n", __FUNCTION__, CcRspNoCarrier->NoCarrier_s);

    for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
        if(MMI_MODEM_CALL_INVALID_INDEX != g_ModemCallMng.CallIndex[i]) {
            break;
        }
    }

    if(i == MODEM_CALL_MAX_CONN) { //no calls
        printf("%s: ignore this msg.\n", __FUNCTION__);
        Hal_Mem_Free(CcRspNoCarrier->NoCarrier_s);
        return;
    }

    if(TRUE == g_ModemCallMng.Ccwa) {
        g_ModemCallMng.Ccwa = FALSE;
        if(0 == g_ModemNwMng[MMI_ModemAdp_Get_UI_SimId(CcRspNoCarrier->SimId)].VolteState) {
            if(1 == g_ModemCallMng.CallConnIndex) {
                MMI_Modem_Call_Response_Disconnect(MMI_ModemAdp_Get_UI_SimId(CcRspNoCarrier->SimId), 2);
            } else {
                MMI_Modem_Call_Response_Disconnect(MMI_ModemAdp_Get_UI_SimId(CcRspNoCarrier->SimId), 1);
            }
        }
        return;
    }

    if(0 == strcmp(CcRspNoCarrier->NoCarrier_s, "NO CARRIER")) {
        IsNoCarrier = 1;
    } else {    //CME ERROR
        IsNoCarrier = 0;
    }

    MMI_Modem_Call_Response_No_Carrier(MMI_ModemAdp_Get_UI_SimId(
                                           CcRspNoCarrier->SimId), MMI_MODEM_CALL_INVALID_INDEX, IsNoCarrier);

    g_ModemCallMng.BufferHangUp = FALSE;
    g_ModemCallMng.RequestDial = FALSE;
    g_ModemCallMng.DualCallPresent                        = FALSE;
    g_ModemCallMng.CallIndex[g_ModemCallMng.FgActiveCall] = MMI_MODEM_CALL_INVALID_INDEX;
    g_ModemCallMng.FgActiveCall                           = 0xFF;
    for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
        if(MMI_MODEM_CALL_INVALID_INDEX != g_ModemCallMng.CallIndex[i]) {
            g_ModemCallMng.FgActiveCall = i;
            break;
        }
    }
    Hal_Mem_Free(CcRspNoCarrier->NoCarrier_s);
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_DIAL
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Dial_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Dial_t * CcRspDial;
    UINT8                               IsOk;

    CcRspDial = (RIL_Modemadp_Cc_Rsp_Dial_t *)Msg;
    printf("%s: RspDial_s=%s\n", __FUNCTION__, CcRspDial->RspDial_s);

    if(0 == strcmp(CcRspDial->RspDial_s, "OK")) {
        IsOk = 0;
    } else {    //CME ERROR
        IsOk = 1;
        g_ModemCallMng.BufferHangUp = FALSE;
        g_ModemCallMng.RequestDial = FALSE;

        Ril_CC_Request_Call_Fail_Cause(MMI_ModemAdp_Get_Ril_SimId(modem_sim_id));
    }

    MMI_Modem_Call_Response_Dial(MMI_ModemAdp_Get_UI_SimId(
                                     CcRspDial->SimId), IsOk);

    Hal_Mem_Free(CcRspDial->RspDial_s);
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_CONN
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Conn_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Conn_t * CcRspConn;

    CcRspConn = (RIL_Modemadp_Cc_Rsp_Conn_t *)Msg;
    MMI_Modem_Call_Response_Connect(MMI_ModemAdp_Get_UI_SimId(
                                        CcRspConn->SimId), g_ModemCallMng.CallIndex[g_ModemCallMng.FgActiveCall]);
    Hal_Mem_Free(CcRspConn->Conn_s);
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_CLIP
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Clip_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Clip_t * CcRspClip;
    MMI_Modem_Call_Response_Clip_t * clip;

    UINT16                         ClipStringLen;
    UINT16                         i, j, k;

    CcRspClip = (RIL_Modemadp_Cc_Rsp_Clip_t *)Msg;
    clip      =
        (MMI_Modem_Call_Response_Clip_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Response_Clip_t));
    ClipStringLen = strlen(CcRspClip->Clip_s);

    // find the <number> postion
    for(i = 0; i < ClipStringLen; i++) {
        if(CcRspClip->Clip_s[i] == ':') {
            break;
        }
    }
    for(j = i; j < ClipStringLen; j++) {
        if(CcRspClip->Clip_s[j] != ' ') {
            break;
        }
    }

    // get <number> value
    clip->number = Hal_Mem_Alloc(MMI_MODEM_MAX_NUMBER_LEN);
    k            = 0;
    for(i = j; i < ClipStringLen; i++) {
        if((CcRspClip->Clip_s[i] != ',') && (k < MMI_MODEM_MAX_NUMBER_LEN)) {
            clip->number[k++] = CcRspClip->Clip_s[i];
        } else {
            break;
        }
    }
    // in case of clip number length longer than the storing array
    if(k == MMI_MODEM_MAX_NUMBER_LEN) {
        for(; i < ClipStringLen; i++) {
            if(CcRspClip->Clip_s[i] != ',') {
                continue;
            } else {
                break;
            }
        }
    }
    i++;

    // get <type> value
    /* 24.008, 10.5.4.7, bit8 = 1
     * Type of number
     *  Bits
     *  7 6 5
     *  0 0 0  unknown
     *  0 0 1  international number
     *  0 1 0  national number
     *  0 1 1  network specific number (Note 4)
     *  1 0 0  dedicated access, short code
     *  1 0 1  reserved
     *  1 1 0  reserved
     *  1 1 1  reserved for extension
     *
     * Numbering plan identification
     * Number plan (applies for type of number = 000, 001, 010 and 100)
     *  Bits
     *  4 3 2 1
     *  0 0 0 0 unknown
     *  0 0 0 1 ISDN/telephony numbering plan (ITU-T Rec. E.164 [45] / ITU-
     *  T Rec. E.163 [44])
     *  0 0 1 1 data numbering plan (ITU-T Rec. X.121 [69])
     *  0 1 0 0 telex numbering plan (ITU-T Rec. F.69 [47])
     *  1 0 0 0 national numbering plan
     *  1 0 0 1 private numbering plan
     *  1 0 1 1 reserved for CTS (see 3GPP TS 44.056 [91])
     *  1 1 1 1 reserved for extension
     */
    clip->type = 0;
    for(; i < ClipStringLen; i++) {
        clip->type *= 10;
        clip->type += CcRspClip->Clip_s[i] - 0x30;
    }

    // find the call index
    if(TRUE == g_ModemCallMng.DualCallPresent) {
        for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
            // in case of dual call, the clip is after ring, so the call is non-FG
            if((MMI_MODEM_CALL_INVALID_INDEX != g_ModemCallMng.CallIndex[i])
                    && (i != g_ModemCallMng.FgActiveCall)) {
                break;
            }
        }
    } else {
        for(i = 0; i < MODEM_CALL_MAX_CONN; i++) {
            if(MMI_MODEM_CALL_INVALID_INDEX != g_ModemCallMng.CallIndex[i]) {
                break;
            }
        }
    }
    MMI_Modem_Call_Response_Clip(MMI_ModemAdp_Get_UI_SimId(
                                     CcRspClip->SimId), g_ModemCallMng.CallIndex[i], clip);
    Hal_Mem_Free(CcRspClip->Clip_s);
} /* MMI_ModemAdp_Ril_CC_Rsp_Clip_Handler */

/**
 * Handler of RIL_MODEMADP_CC_RSP_CMUT
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Cmut_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Cmut_t * CcRspCmut = NULL;
    MMI_Modem_Call_Response_Cmut_t * cmut = NULL;

    CcRspCmut = (RIL_Modemadp_Cc_Rsp_Cmut_t *)Msg;

    cmut      =
        (MMI_Modem_Call_Response_Cmut_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Response_Cmut_t));
    Hal_Mem_Set(cmut, 0, sizeof(MMI_Modem_Call_Response_Cmut_t));

    if(RIL_E_SUCCESS == CcRspCmut->result) {
        cmut->mute = CcRspCmut->mute;
    } else {
        cmut->error = (int32_t)CcRspCmut->result;
    }

    MMI_Modem_Call_Response_Cmut(MMI_ModemAdp_Get_UI_SimId(CcRspCmut->SimId), cmut);
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_GET_IMEI
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Get_Imei_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Get_Imei_t * CcRspGetImei = NULL;
    char * imei;
    UINT8 len;

    CcRspGetImei = (RIL_Modemadp_Cc_Rsp_Get_Imei_t *)Msg;

    if(RIL_E_SUCCESS == CcRspGetImei->result) {
        if('"' == *CcRspGetImei->p_imei) {
            imei = CcRspGetImei->p_imei + 1;
            len = strlen(CcRspGetImei->p_imei) - 2;
        } else {
            imei = CcRspGetImei->p_imei;
            len = strlen(CcRspGetImei->p_imei);
        }
        g_ModemCallMng.Imei[MMI_ModemAdp_Get_UI_SimId(CcRspGetImei->SimId)] = (INT8 *)Hal_Mem_Alloc(len + 1);
        Hal_Mem_Set(g_ModemCallMng.Imei[MMI_ModemAdp_Get_UI_SimId(CcRspGetImei->SimId)], 0, len + 1);
        Hal_Mem_Copy(g_ModemCallMng.Imei[MMI_ModemAdp_Get_UI_SimId(CcRspGetImei->SimId)], imei, len);
    } else {
        if(NULL != g_ModemCallMng.Imei[MMI_ModemAdp_Get_UI_SimId(CcRspGetImei->SimId)]) {
            Hal_Mem_Free(g_ModemCallMng.Imei[MMI_ModemAdp_Get_UI_SimId(CcRspGetImei->SimId)]);
        }
    }

    if(NULL != CcRspGetImei->p_imei) {
        Hal_Mem_Free(CcRspGetImei->p_imei);
    }
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_BASEBAND_VERSION
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Baseband_Ver_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Baseband_Version_t * CcRspGetBasebandVer = NULL;
    char * basebandver;
    UINT8 len;
    UINT8 i,j;

    CcRspGetBasebandVer = (RIL_Modemadp_Cc_Rsp_Baseband_Version_t *)Msg;

    if(RIL_E_SUCCESS == CcRspGetBasebandVer->result) {
        if('"' == *CcRspGetBasebandVer->p_basebandver) {
            basebandver = CcRspGetBasebandVer->p_basebandver + 1;
            len = strlen(CcRspGetBasebandVer->p_basebandver) - 2;
        } else {
            basebandver = CcRspGetBasebandVer->p_basebandver;
            len = strlen(CcRspGetBasebandVer->p_basebandver);
        }
        for(i = 0;i < len;i ++)
        {
            if(0 == strncmp("SDK",&(basebandver[i]),3))
            {
                break;
            }
        }
        for (j = i+4; j < len; j++)
        {
            if(0 == strncmp("_",&(basebandver[j]),1))
            {
                break;
            }
        }
        len = j - i;
        g_ModemCallMng.BasebandVer = (INT8 *)Hal_Mem_Alloc(len + 1);
        Hal_Mem_Set(g_ModemCallMng.BasebandVer, 0, len + 1);
        Hal_Mem_Copy(g_ModemCallMng.BasebandVer, &(basebandver[i]), len);
        printf("%s:BasebandVer is %s,len is %d\n",__FUNCTION__,g_ModemCallMng.BasebandVer,len);
    }

    if(NULL != CcRspGetBasebandVer->p_basebandver) {
        Hal_Mem_Free(CcRspGetBasebandVer->p_basebandver);
    }
}

/**
 * Handler of RIL_MODEMADP_CC_RSP_CEER
 * param (in) Msg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_Ril_CC_Rsp_Ceer_Handler(UI_Inter_Msg_t * Msg)
{
    RIL_Modemadp_Cc_Rsp_Ceer_t * CcRspCeer;
    UINT16 CeerStringLen;
    char *Ceer;

    CcRspCeer = (RIL_Modemadp_Cc_Rsp_Ceer_t *)Msg;
    printf("%s: %s\n", __FUNCTION__, CcRspCeer->RspCeer_s);

    CeerStringLen = strlen(CcRspCeer->RspCeer_s);
    Ceer = Hal_Mem_Alloc(CeerStringLen + 1);
    strncpy(Ceer, CcRspCeer->RspCeer_s, CeerStringLen + 1);

    MMI_Modem_Call_Response_Ceer(MMI_ModemAdp_Get_UI_SimId(CcRspCeer->SimId), Ceer);

    Hal_Mem_Free(CcRspCeer->RspCeer_s);
}

/**
 * module event handler
 * param (in) MsgId: UI_INTER_MSG_ID
 *       (in) pMsg: UI_Inter_Msg_t*
 * return  void
 */
VOID MMI_ModemAdp_CC_Msg_handle(UI_INTER_MSG_ID MsgId, UI_Inter_Msg_t * pMsg)
{
    switch(MsgId) {
        case MMI_MODEMADP_CALL_DIAL:
            MMI_ModemAdp_Call_Dial_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_HANGUP:
            MMI_ModemAdp_Call_Hangup_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_HANGUP_WAITING_OR_BG:
            MMI_ModemAdp_Call_Hangup_Waiting_Or_Bg_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_HANGUP_FG_RESUME_BG:
            MMI_ModemAdp_Call_Hangup_Fg_Resume_Bg_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE:
            MMI_ModemAdp_Call_Switch_WaitingOrHolding_And_Active_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_CONF:
            MMI_ModemAdp_Call_Conference_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_SEPERATE_CONN:
            MMI_ModemAdp_Call_Seperate_Conn_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_EXPLICIT_CALL_TRANSFER:
            MMI_ModemAdp_Call_Explicit_Call_Transfer_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_UDUB:
            MMI_ModemAdp_Call_Udub_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_ANSWER:
            MMI_ModemAdp_Call_Answer_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_DTMF:
            MMI_ModemAdp_Call_Dtmf_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_DTMF_START:
            MMI_ModemAdp_Call_Dtmf_Start_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_DTMF_STOP:
            MMI_ModemAdp_Call_Dtmf_Stop_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_SET_MUTE:
            MMI_ModemAdp_Call_Set_Mute_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_REQUEST_IMEI:
            MMI_ModemAdp_Call_Request_Imei_Handler(pMsg);
            break;

        case MMI_MODEMADP_CALL_REQUEST_BASEBAND_VERSION:
            MMI_ModemAdp_Call_Request_Baseband_Version_Handler(pMsg);
            break;

        // case MMI_MODEMADP_CALL_GET_CURRENT_CALLS:
        // case MMI_MODEMADP_CALL_GET_MUTE:

        case RIL_MODEMADP_CC_RSP_CLCC:
            MMI_ModemAdp_Ril_CC_Rsp_Clcc_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_CCWA:
            MMI_ModemAdp_Ril_CC_Rsp_Ccwa_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_RING:
            // case RIL_MODEMADP_CC_RSP_CRING:
            MMI_ModemAdp_Ril_CC_Rsp_Ring_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_GET_CUR_CALLS:
            MMI_ModemAdp_Ril_CC_Rsp_Get_Cur_Calls_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_CALL_DISCONNECT:
            MMI_ModemAdp_Ril_CC_Rsp_Call_Disconnect_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_NO_CARRIER:
            MMI_ModemAdp_Ril_CC_Rsp_No_Carrier_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_DIAL:
            MMI_ModemAdp_Ril_CC_Rsp_Dial_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_CONN:
            MMI_ModemAdp_Ril_CC_Rsp_Conn_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_CLIP:
            MMI_ModemAdp_Ril_CC_Rsp_Clip_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_CMUT:
            MMI_ModemAdp_Ril_CC_Rsp_Cmut_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_GET_IMEI:
            MMI_ModemAdp_Ril_CC_Rsp_Get_Imei_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_BASEBAND_VERSION:
            MMI_ModemAdp_Ril_CC_Rsp_Baseband_Ver_Handler(pMsg);
            break;

        case RIL_MODEMADP_CC_RSP_CEER:
            MMI_ModemAdp_Ril_CC_Rsp_Ceer_Handler(pMsg);
            break;

        default:
            break;
    } /* switch */
}     /* MMI_ModemAdp_Call_Event_handle */

/**
 * Get UI Call State
 * param (in) RilCallState: RIL_CallState
 * return  MMI_MODEM_CALL_STATE
 */
MMI_MODEM_CALL_STATE MMI_ModemAdp_Get_UI_Call_State(RIL_CallState RilCallState)
{
    switch(RilCallState) {
        case RIL_CALL_ACTIVE:
            return(MMI_MODEM_CALL_STATE_ACTIVE);

        case RIL_CALL_HOLDING:
            return(MMI_MODEM_CALL_STATE_HOLDING);

        case RIL_CALL_DIALING:
            return(MMI_MODEM_CALL_STATE_DIALING);

        case RIL_CALL_ALERTING:
            return(MMI_MODEM_CALL_STATE_ALERTING);

        case RIL_CALL_INCOMING:
            return(MMI_MODEM_CALL_STATE_INCOMING);

        case RIL_CALL_WAITING:
            return(MMI_MODEM_CALL_STATE_WAITING);

        case RIL_CALL_INVALID:
            return(MMI_MODEM_CALL_STATE_INVALID);

        default:
            return(MMI_MODEM_CALL_STATE_NULL);
    }
}

/**
 * Queries the current call active status
 * param void
 * return  bool
 */
BOOL MMI_ModemAdp_Call_Get_Call_Active_Status(VOID)
{
    BOOL ret = TRUE;

    if(0xFF == g_ModemCallMng.FgActiveCall) {
        ret = FALSE;
    }

    return ret;
}

void Ril_CC_Response_Get_Mute(RIL_SIM_ID sid, int * mute, RIL_Errno result)
{
    RIL_Modemadp_Cc_Rsp_Cmut_t * pMsg = NULL;
    if(gcf_test) {
        Hal_Mem_Free(mute);
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Cmut_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Cmut_t));
    Hal_Mem_Set(pMsg, 0, sizeof(RIL_Modemadp_Cc_Rsp_Cmut_t));

    pMsg->SimId  = sid;
    pMsg->mute   = *mute;
    pMsg->result = result;

    Hal_Mem_Free(mute);
    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_CMUT, (UI_Inter_Msg_t *)pMsg);
}

void Ril_DEV_Response_Get_Imei(RIL_SIM_ID simId, char * p_imei, RIL_Errno result)
{
    RIL_Modemadp_Cc_Rsp_Get_Imei_t * pMsg = NULL;

    printf("##interface## %s\n", __FUNCTION__);

    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Get_Imei_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Get_Imei_t));
    Hal_Mem_Set(pMsg, 0, sizeof(RIL_Modemadp_Cc_Rsp_Get_Imei_t));

    pMsg->SimId  = simId;
    pMsg->p_imei = p_imei;
    pMsg->result = result;

    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_GET_IMEI, (UI_Inter_Msg_t *)pMsg);
}

void Ril_DEV_Response_Baseband_Version(RIL_SIM_ID simId, char * p_basebandver, RIL_Errno result)
{
    RIL_Modemadp_Cc_Rsp_Baseband_Version_t * pMsg = NULL;

    printf("##interface## %s\n", __FUNCTION__);

    if(gcf_test) {
        return;
    }

    pMsg =
        (RIL_Modemadp_Cc_Rsp_Baseband_Version_t *)Hal_Mem_Alloc(sizeof(RIL_Modemadp_Cc_Rsp_Baseband_Version_t));
    Hal_Mem_Set(pMsg, 0, sizeof(RIL_Modemadp_Cc_Rsp_Baseband_Version_t));

    pMsg->SimId  = simId;
    pMsg->p_basebandver = p_basebandver;
    pMsg->result = result;

    UI_Send_Inter_Msg(UI_SUB_MODULE_MODEM_ADP, RIL_MODEMADP_CC_RSP_BASEBAND_VERSION, (UI_Inter_Msg_t *)pMsg);
}

#endif // USE_LV_WATCH_MODEM_ADAPTOR
